﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AlbumAdd : System.Web.UI.Page
{

    private readonly AMV.BLL.Album albumBll = new AMV.BLL.Album();

    protected void Page_Load(object sender, EventArgs e)
    {
        BindPublishYears();
        
    }


    private void BindPublishYears()
    {
        int year = DateTime.Now.Year;

        ddlPublishYear.Items.Add(new ListItem("请选择", ""));
        for (int i = 0; i < 6; i++)
        {
            ddlPublishYear.Items.Add(new ListItem((year - i).ToString(), (year - i).ToString()));
        }
        ddlPublishYear.SelectedIndex = 0;
    }

    protected void ddlStyle_DataBound(object sender, EventArgs e)
    {
        ddlStyle.Items.Insert(0, new ListItem("请选择", ""));
        ddlStyle.SelectedIndex = 0;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!IsValid) return;

        AMV.Model.Album album = new AMV.Model.Album();

        album.AlbumName = txtAlbumName.Text.Trim();
        album.Language = ddlLanguage.SelectedValue;
        album.SingerName = txtSingerName.Text.Trim();

        int numberOfSongs = 0;
        int.TryParse(txtNumberOfSongs.Text, out numberOfSongs);
        album.NumberOfSongs = numberOfSongs;

        album.Description = txtDescription.Text.Trim();

        int publishYear = 0;
        int.TryParse(ddlPublishYear.SelectedValue, out publishYear);
        album.PublishYear = publishYear;

        album.Style = ddlStyle.SelectedValue;

        if (albumBll.Add(album) > 0)
        {
            MessageBox.ShowMessageAndGoLocation(this, "添加成功", ResolveUrl("./AlbumList.aspx"));
        }
        else
        {
            MessageBox.ShowMessage(this, "添加失败");
        }
    }
}